package com.quicks.beauty.server.web;

import com.quicks.beauty.core.vo.BeautyProductDetailVO;
import com.quicks.beauty.core.vo.BeautyProductVO;
import com.quicks.beauty.server.common.AjaxResult;
import com.quicks.beauty.server.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "prod")
@Api(tags = "获取商品")
public class ProductController extends BaseController {

    @Autowired
    private ProductService productService;


    /**
     * 商品列表
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping(value = "list")
    @ApiOperation(value = "商品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页面，", paramType = "query", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "数量，", paramType = "query", required = true, dataType = "Integer")
    })
    public AjaxResult getProdItemList(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        AjaxResult result = new AjaxResult();
        pageNum = pageNum == null ? super.pageNum : pageNum;
        pageSize = pageSize == null ? super.pageSize : pageSize;

        List<BeautyProductVO> productList = null;
        try {
            productList = productService.getAllBeautyProdPager(pageNum, pageSize);
            result.setSuccess(true);
            result.setData(productList);
            result.setMsg("ok");
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMsg("系统打盹,请稍后...");
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 获取当前礼品详情
     *
     * @param prodId
     * @return
     */
    @ApiOperation(value = "获取当前礼品详情")
    @RequestMapping(value = "item", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "prodId", value = "礼品ID，", paramType = "query", required = true, dataType = "Integer")
    })
    public AjaxResult getProdItem(@RequestParam("prodId")String prodId){
        AjaxResult result = new AjaxResult();
        try {
            BeautyProductDetailVO vo = productService.getProdItemDetailVo(prodId);
            result.setSuccess(true);
            result.setData(vo);
            result.setMsg("ok");
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMsg("系统打盹,请稍后...");
            e.printStackTrace();
        }
        return result;
    }
}
